package com.kangkang.shixi;

import java.util.ArrayList;
import java.util.List;

public class StudentClass implements Comparable<StudentClass> {
    private String name;
    private float AvgScores;
    private List<Student> studentList = new ArrayList<>();
    ;

    public StudentClass(String name) {
        this.name = name;
    }

    public void addStudent(Student s) {
        this.studentList.add(s);
    }

    public void computeAvgScores() {
        float classSumScores = 0;
        for (Student student : studentList) {
            classSumScores += student.getSumScore();
        }
        this.AvgScores = classSumScores / studentList.size();
    }

    @Override
    public int compareTo(StudentClass o) {
        if (this.AvgScores != this.AvgScores) {
            if (this.AvgScores < o.AvgScores) return 1;
        }
        return -1;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getAvgScores() {
        return AvgScores;
    }

    public void setAvgScores(float avgScores) {
        AvgScores = avgScores;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    @Override
    public String toString() {
        return "StudentClass{" +
                "name='" + name + '\'' +
                ", AvgScores=" + AvgScores +
                ", studentList=" + studentList +
                '}';
    }
}
